<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>智能客服</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html, body {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    
    #chat-container {
      width: 100%;
      height: 100%;
    }
    
    iframe {
      width: 100%;
      height: 100%;
      border: none;
    }
  </style>
</head>
<body>
  <div id="chat-container">
    <!-- iframe 将在这里动态插入 -->
  </div>
  
  <script>
    // 获取 token（可以通过 URL 参数传递）
    const urlParams = new URLSearchParams(window.location.search);
    const token = urlParams.get('token') || 'i1LpZ1l6t3c8hVYp';
    
    // 构建 iframe URL
    const iframeUrl = `https://udify.app/chatbot/${token}`;
    
    // 创建并插入 iframe
    const iframe = document.createElement('iframe');
    iframe.src = iframeUrl;
    iframe.allow = 'microphone';
    document.getElementById('chat-container').appendChild(iframe);
    
    // 与 uni-app 通信
    function sendMessageToUniApp(data) {
      if (window.uni && window.uni.postMessage) {
        window.uni.postMessage({
          data: data
        })
      }
    }
    
    // 监听来自 uni-app 的消息
    window.addEventListener('message', function(event) {
      console.log('收到消息:', event.data)
    })
    
    // 监听 iframe 加载
    iframe.onload = function() {
      console.log('聊天机器人加载成功');
      sendMessageToUniApp({ type: 'loaded' });
    }
    
    iframe.onerror = function() {
      console.error('聊天机器人加载失败');
      sendMessageToUniApp({ type: 'error' });
    }
  </script>
</body>
</html>

